<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>用户注册</title>
    <link rel="stylesheet" href="css/style.css">
    <style>
        body {
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
        }
        .container {
            background-color: white;
            padding: 24px;
            border-radius: 12px;
            box-shadow: 0 6px 16px rgba(0,0,0,0.08);
            width: 400px;
        }
        .tab {
            overflow: hidden;
            border: 1px solid #E1E5EB;
            background-color: var(--light);
        }
        .tab button {
            background-color: inherit;
            float: left;
            border: none;
            outline: none;
            cursor: pointer;
            padding: 14px 16px;
            transition: 0.3s;
        }
        .tab button:hover {
            background-color: #ddd;
        }
        .tab button.active {
            background-color: #ccc;
        }
        .tabcontent {
            display: none;
            padding: 6px 12px;
            border: 1px solid #ccc;
            border-top: none;
        }
        .form-group {
            margin-bottom: 15px;
        }
        label {
            display: block;
            margin-bottom: 5px;
        }
        input[type="text"], input[type="email"], input[type="password"], input[type="tel"] {
            width: 100%;
            padding: 8px;
            box-sizing: border-box;
        }
        button[type="submit"] {
            background-color: #4CAF50;
            color: white;
            padding: 10px 15px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
        }
        button[type="submit"]:hover {
            background-color: #45a049;
        }
        .verification-code {
            display: flex;
            gap: 10px;
        }
        .verification-code input {
            flex: 1;
        }
        .verification-code button {
            padding: 8px;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="tab">
            <button class="tablinks active" onclick="openTab(event, 'company')">企业招聘者注册</button>
            <button class="tablinks" onclick="openTab(event, 'jobSeeker')">应聘者注册</button>
            
        </div>

        <div id="company" class="tabcontent" style="display: block;">
            <form id="companyRegisterForm">
                <div class="form-group">
                    <label for="companyName">企业名称</label>
                    <input type="text" id="companyName" required
                           pattern="^[\u4e00-\u9fa5]+$"
                           title="请输入有效的中文企业名称">
                </div>
                <div class="form-group">
                    <label for="companyEmail">企业邮箱</label>
                    <input type="email" id="companyEmail" required
                           pattern="^[a-zA-Z][\w.-]*@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$"
                           title="请输入有效的企业邮箱地址（字母开头，包含@和域名）">
                </div>
                <div class="form-group verification-code">
                    <input type="text" id="companyVerificationCode" placeholder="验证码">
                    <button type="button" onclick="sendVerificationCode('companyEmail')">获取验证码</button>
                </div>
                <div class="form-group">
                    <label for="companyPassword">密码</label>
                    <input type="password" id="companyPassword" required
                           minlength="8"
                           pattern="^(?=.*[a-z])(?=.*[A-Z])(?=.*\d).{8,}$"
                           title="密码必须包含大小写字母和数字，至少8位">
                </div>
                <button type="submit">注册</button>
            </form>
        </div>

        <div id="jobSeeker" class="tabcontent">
            <form id="jobSeekerRegisterForm">
                <div class="form-group">
                    <label for="jobSeekerName">姓名</label>
                    <input type="text" id="jobSeekerName" required
                           pattern="^[\u4e00-\u9fa5a-zA-Z]+$"
                           title="请输入有效姓名（仅中文或字母）">
                </div>
                <div class="form-group">
                    <label for="jobSeekerPhone">手机号</label>
                    <input type="tel" id="jobSeekerPhone" required
                           pattern="^1[3-9]\d{9}$"
                           title="请输入有效的11位手机号">
                </div>
                <div class="form-group verification-code">
                    <input type="text" id="jobSeekerVerificationCode" placeholder="验证码">
                    <button type="button" onclick="sendVerificationCode('jobSeekerPhone')">获取验证码</button>
                </div>
                <div class="form-group">
                    <label for="jobSeekerPassword">密码</label>
                    <input type="password" id="jobSeekerPassword" required
                           minlength="8"
                           pattern="^(?=.*[a-z])(?=.*[A-Z])(?=.*\d).{8,}$"
                           title="密码必须包含大小写字母和数字，至少8位">
                </div>
                <button type="submit">注册</button>
            </form>
        </div>

        
    </div>


<script src="js/auth.js"></script>
  <script>
        window.openTab = function(evt, tabName) {
            var i, tabcontent, tablinks;
            tabcontent = document.getElementsByClassName("tabcontent");
            for (i = 0; i < tabcontent.length; i++) {
                tabcontent[i].style.display = "none";
            }
            tablinks = document.getElementsByClassName("tablinks");
            for (i = 0; i < tablinks.length; i++) {
                tablinks[i].className = tablinks[i].className.replace(" active", "");
            }
            document.getElementById(tabName).style.display = "block";
            if (evt) {
                evt.currentTarget.className += " active";
            } else {
                // 当无事件对象时，通过标签名查找并激活对应按钮
                for (var j = 0; j < tablinks.length; j++) {
                    if (tablinks[j].getAttribute("onclick").includes(tabName)) {
                        tablinks[j].className += " active";
                        break;
                    }
                }
            }
        }

        window.sendVerificationCode = function(fieldId) {
            const field = document.getElementById(fieldId);
            if (field.value) {
                // 实际开发中需要实现发送验证码的逻辑
                alert(`验证码已发送至 ${field.value}`);
            } else {
                alert('请先填写邮箱或手机号');
            }
        }

        

        document.getElementById('companyRegisterForm').addEventListener('submit', function(e) {
            e.preventDefault();
            
            const form = e.target;
            if (!form.checkValidity()) {
                alert('请填写正确的表单信息');
                return;
            }
            // 获取表单数据
            const companyName = document.getElementById('companyName').value;
            const companyEmail = document.getElementById('companyEmail').value;
            const companyPassword = document.getElementById('companyPassword').value;
            
            // 保存到localStorage
            const companyUsers = JSON.parse(localStorage.getItem('companyUsers') || '[]');
            // 企业注册逻辑保持不变
            companyUsers.push({
                name: companyName,
                email: companyEmail,
                password: companyPassword
            });
            localStorage.setItem('companyUsers', JSON.stringify(companyUsers));
            
            alert('企业注册成功，即将跳转到企业招聘页面');
            setTimeout(() => window.location.href = 'company-recruitment.html', 1500);
        });


        document.getElementById('jobSeekerRegisterForm').addEventListener('submit', function(e) {
            e.preventDefault();
            
            const form = e.target;
            if (!form.checkValidity()) {
                alert('请填写正确的表单信息');
                return;
            }
            // 实际开发中需要实现求职者注册逻辑
            alert('应聘者注册成功，即将跳转到个人中心');
            setTimeout(() => window.location.href = 'job-seeker-dashboard.html', 1500);
        });

            function autoSelectTab() {
            const urlParams = new URLSearchParams(window.location.search);
            const role = urlParams.get('role');
            let tabButton;
            if (role === 'company') {
                tabButton = document.querySelector('[onclick="openTab(event, \'company\')"]');
            } else if (role === 'jobSeeker') {
                tabButton = document.querySelector('[onclick="openTab(event, \'jobSeeker\')"]');
            }
            if (tabButton) {
                tabButton.click();
            } else {
                document.getElementsByClassName('tablinks')[0].click();
            }
        }
        document.addEventListener('DOMContentLoaded', autoSelectTab);
    </script>
</body>
</html>